﻿var wmsSource = new ol.source.TileWMS({
    //url: 'http://demo.opengeo.org/geoserver/wms',
    //params: { 'LAYERS': 'ne:ne' }
    url: 'http://localhost:6666/geoserver/LiuG/wms',
    params:
    {
        'LAYERS': 'LiuG:bou2',
    'format': 'image/png',
    },
});

var wmsLayer = new ol.layer.Tile({
    source: wmsSource
});

var view = new ol.View2D({
    center: [0, 0],
    zoom: 1
});

var viewProjection = /** @type {ol.proj.Projection} */
    (view.getProjection());

var map = new ol.Map({
    layers: [wmsLayer],
    target: 'map',
    view: view
});

var layer2 = new ol.layer.Tile
        ({
            source: new ol.source.TileWMS
                ({
                    url: 'http://localhost:6666/geoserver/LiuG/wms',
                    params:
                        {
                            'layers': 'LiuG:globe6',
                            'format': 'image/png',
                        },
                    maxZoom: 22,
                }),
            layerName: '全球谷歌数据前6级'
        });
//map.addLayer(layer2);

map.on('singleclick', function (evt)
{
    document.getElementById('info').innerHTML = '';
    var viewResolution = /** @type {number} */ (view.getResolution());
    var url = wmsSource.getGetFeatureInfoUrl(
        evt.coordinate, viewResolution, viewProjection,
        { 'INFO_FORMAT': 'text/html' });
    if (url)
    {
        document.getElementById('info').innerHTML =
            '<iframe seamless src="' + url + '"></iframe>';
    }
});
